
{extends file="../acp.html"}

{block name="title"}{$head_title}{/block}
{block name="content"}
<script>
    function no_pic(obj) {
        obj.setAttribute("src", "/Public/Images/acp/nopicture.jpg");
    }
</script>

<div class="tablesWrap">
    <div class="tables-searchbox">
        <form method="post">
            <span class="tbs-txt">帖子名称：</span>
            <input type="text" name="post_name" value="{$post_name}">

            <span class="tbs-txt">发帖人：</span>
            <input type="text" name="user_name" value="{$user_name}">

            <select name="channel_id">
                <option value="">-所属频道-</option>
                {foreach from=$channel_list item=v}
                <option value="{$v.channel_id}" {if $channel_id == $v.channel_id}selected{/if}>{$v.channel_name}</option>
                {/foreach}
            </select>

            <button type="submit" class="btn"><i class="gicon-search"></i>搜索</button>
        </form>
    </div>
    <!-- end tables-searchbox -->
    <table class="wxtables">
        <colgroup>
            <!-- <col width="7%"> -->
            <col width="7%">
            <col width="7%">
            <col width="7%">
            <col width="7%">
            <col width="15%">
        </colgroup>
        <thead>
        <tr>
            <!-- <td>选择</td> -->
            <td>帖子名称</td>
            <td>所属频道</td>
            <td>发布人</td>
            <td>发布时间</td>
            <td>操作</td>
        </tr>
        </thead>
        <tbody>
        {foreach from=$post_list  item=v }
        <tr>
            <!-- <td><input type="checkbox" class="checkbox" value="{$incubator.incubator_id}" name="checkIds[]"></td> -->
            <td>{$v.title}</td>
            <td>{$v.channel_name}</td>
            <td>{$v.post_user.nickname}</td>
            <td>{$v.acp_time}</td>
            <td>
                {if !$v.is_del}
                <!--wangtao 2017.9.15 -start-->
                {if !$v.is_featured}
                <a href="javascript:;" onclick="set_featured({$v.post_id});" class="btn" title="设置精选">设置精选</a>
                {else}
                <a href="javascript:;" onclick="del_featured({$v.post_id});" class="btn" title="取消精选">取消精选</a>
                {/if}
                <!--wangtao 2017.9.15 -end-->
                <a href="javascript:;" class="btn" onclick='post_link({$v.post_id})' title="复制链接">复制链接</a>
                <a href="javascript:;" onclick="del_post({$v.post_id});" class="btn" title="删除"><i class="gicon-trash black"></i>删除</a>
                <!--wangtao 2017.9.15 -start-->
                {else}
                <a href="javascript:;" onclick="recover_post({$v.post_id});" class="btn" title="恢复">恢复</a>
                {/if}
                <!--wangtao 2017.9.15 -end-->
                <a href="/AcpPost/{$v.detail_url}/post_id/{$v.post_id}" class="btn" title="详情"><i class="gicon-edit black"></i>详情</a>
                <a href="/AcpPost/{$v.url_comment_list}/post_id/{$v.post_id}" class="btn" title="查看评论"><i class="icon-comments black"></i>查看评论</a>
            </td>
        </tr>
        {foreachelse}
        <tr><td colspan="10">没有找到任何记录</td></tr>
        {/foreach}
        </tbody>
    </table>
    <!-- end wxtables -->
    <div class="tables-btmctrl clearfix">
        <!-- <div class="fl">
            <a href="javascript:selall()" class="btn btn-blue">全选</a>
            <a href="javascript:clearall()" class="btn btn-blue">取消</a>
            <a href="javascript:;" class="btn btn-blue J_batch_store">下架</a>
            <a href="javascript:;" class="btn btn-blue" onclick="delIncubatorBatch()">删除</a>
        </div> -->
        <div class="fr">
            <div class="paginate">
                {$show}
            </div>
            <!-- end paginate -->
        </div>
    </div>
    <!-- end tables-btmctrl -->
</div>
<!-- end tablesWrap -->
{/block}

{block name="js"}
<script src="/Public/Plugins/My97DatePicker/WdatePicker.js?version={$version}"></script>
<script src="__JS__/front/jquery.showLoading.min.js?version={$version}"></script>
<script src="__JS__/clipboard.min.js"></script>
<link rel="stylesheet" href="__CSS__/front/showLoading.css?version={$version}">
{literal}
<script>
    function post_link(post_id)
    {
//        var link = 'http://' + document.domain + '/FrontChannel/post_detail/post_id/' + post_id;
         var link = '/FrontChannel/post_detail/post_id/' + post_id;
        $.jPops.custom({
            title:"请复制链接",
            content:'<div>帖子的链接：' + link + '</div>',
            okBtnTxt:"复制",
            cancelBtnTxt:"关闭",
            callback:function(r)
            {
                if(r)
                {
                    text = link;
                    copy_text('jpops-btn-ok');
                }
                else
                {
                    return true;
                }
            }
        });
    }
    function copy_text(id)
    {
        var clipboard = new Clipboard('#' + id, {
            text: function() {
                return text;
            }
        });

        clipboard.on('success', function(e) {
            console.log(e);
            alert('复制成功');
        });

        clipboard.on('error', function(e) {
            console.log(e);
            alert('复制失败，请手动复制');
        });
    }
    <!--wangtao 2017.9.15 -start-->
    function set_featured(post_id)
    {
        var html = "确认将这个帖子设置成精选吗?";
        $.jPops.custom({
            title:"设置精选帖子",
            content:html,
            okBtnTxt:"确定",
            cancelBtnTxt:"取消",
            callback:function(r)
            {
                if(r)
                {
                    $.post('/AcpPost/set_featured',{'post_id':post_id},function(data) {
                        console.log(data)
                        if (data == 'success') {
                            alert('设置成功');
                            location.reload();
                        } else {
                            alert('设置失败，有另一个帖子被设置成精选贴，请稍后再试');
                        }
                    });
                }
                return true;
            }
        });
    }

    function del_featured(post_id)
    {
        var html = "确认将这个帖子删除精选吗?";
        $.jPops.custom({
            title:"删除精选帖子",
            content:html,
            okBtnTxt:"确定",
            cancelBtnTxt:"取消",
            callback:function(r)
            {
                if(r)
                {
                    $.post('/AcpPost/del_featured',{'post_id':post_id},function(data) {
                        console.log(data)
                        if (data == 'success') {
                            alert('删除精选成功');
                            location.reload();
                        } else {
                            alert('删除精选失败，请稍后再试');
                        }
                    });
                }
                return true;
            }
        });
    }

    <!--wangtao 2017.9.15 -end-->

    function del_post(post_id)
    {
        var html = "确认删除这个帖子吗?";
        $.jPops.custom({
            title:"删除帖子",
            content:html,
            okBtnTxt:"确定",
            cancelBtnTxt:"取消",
            callback:function(r)
            {
                if(r)
                {
                    $.post('/AcpPost/del_post',{'post_id':post_id},function(data) {
                        console.log(data)
                        if (data == 'success') {
                            alert('删除成功');
                            location.reload();
                        } else {
                            alert('删除失败，请稍后再试');
                        }
                    });
                }
                return true;
            }
        });
    }
    <!--wangtao 2017.9.15 -start-->
    function recover_post(post_id)
    {
        var html = "确认恢复这个帖子吗?";
        $.jPops.custom({
            title:"恢复帖子",
            content:html,
            okBtnTxt:"确定",
            cancelBtnTxt:"取消",
            callback:function(r)
            {
                if(r)
                {
                    $.post('/AcpPost/recover_post',{'post_id':post_id},function(data) {
                        console.log(data)
                        if (data == 'success') {
                            alert('恢复成功');
                            location.reload();
                        } else {
                            alert('恢复失败，请稍后再试');
                        }
                    });
                }
                return true;
            }
        });
    }
    <!--wangtao 2017.9.15 -end-->
</script>
{/literal}
{/block}
